package com.atguigu.cmsservice.service.impl;

import com.atguigu.cmsservice.entity.CrmBanner;
import com.atguigu.cmsservice.mapper.CrmBannerMapper;
import com.atguigu.cmsservice.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author zr
 * @since 2021-11-17
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {
    /**
     * 查询所有的Banner
     *
     * @return
     */
    @Cacheable(value = "banner", key = "'selectIndexList'")
    @Override
    public List<CrmBanner> findAllBanner() {
        // 根据Id进行降序排序  只显示前两条记录
        QueryWrapper<CrmBanner> queryWrapper = new QueryWrapper<>();
        // 按Id进行排序
        queryWrapper.orderByDesc("id");
        // 拼接sql语句
        queryWrapper.last("limit 2");
        List<CrmBanner> crmBannerList = baseMapper.selectList(queryWrapper);
        return crmBannerList;
    }
}
